// ### 作业：建一个用户表（有姓名,年龄,性别,创建时间,修改时间）,使用模块加mysql模块,实现对数据的增删改查

// ###       修改时记得，把修改时间改成修改时的时间，能实现分页（选做）
let sql = require('mysql');
let mysql= sql.createConnection({host:'127.0.0.1',user:'root',password:'root',port:'3306',database:'yyy'})
mysql.connect();
//增
var newdate=new Date().toLocaleString();
let addsql="INSERT INTO `yyy`.`biao` (`id`, `name`, `age`, `creattime`, `updatetime`) VALUES (3, 'w', 1, '"+newdate+"', '"+newdate+"')"
mysql.query(addsql,(err,date)=>{
    if(date!=undefined){
        console.log("添加成功");
    }
})
//删
let delsql="DELETE FROM `yyy`.`biao` WHERE `id` = 3"
mysql.query(delsql,(err,date)=>{
    if(date.affectedRows!=0){
        console.log("删除成功");
    }
})
//改
var newdate=new Date().toLocaleString();
let updatesql="UPDATE `yyy`.`biao` SET `name` = 'G', `updatetime` = '"+newdate+"' WHERE `id` = 1"
mysql.query(updatesql,(err,date)=>{
    if(date.affectedRows!=0){
        console.log("修改成功");
    }
})
//查
var ye = 2; //假设第二页
selectsql = "SELECT * FROM `yyy`.`biao` LIMIT "+2*(ye-1) +",2"
mysql.query(selectsql,(err,date)=>{
    console.log(date);
})



mysql.end();
